package com.ld.common.util.notice.plugin;

import com.ld.common.plugin.Plugin;
import com.ld.common.plugin.PluginInfo;
import com.ld.common.util.notice.NoticeManager;
import com.ld.common.util.notice.NoticeModel;
import com.ld.shieldsb.common.core.model.PropertiesModel;
import com.ld.shieldsb.common.core.model.Result;
import com.ld.shieldsb.common.core.util.notice.WeChatUtil;

public class EpWeChatNoticeUtil implements Plugin {
    private PluginInfo pluginInfo = new PluginInfo("企业微信通知插件", this); // 插件信息
    public static final String NOTICE_TYPE = "EnterpriseWeChatNotice";

    public static final NoticeModel NOTICE = new NoticeModel("企业微信通知", NOTICE_TYPE) {

        @Override
        public Result notice(String signName, String sendTo, String subject, String content, Object otherParams) {
            // 注意下面参数需要到企业微信中获取
            String corpid = PropertiesModel.CONFIG.getString("notice.ewechat.client-id");
            String corpsecret = PropertiesModel.CONFIG.getString("notice.ewechat.client-secret");
            String agentid = PropertiesModel.CONFIG.getString("notice.ewechat.agent-id");

            Result flag = WeChatUtil.sendEnterpriseWeChatMsg(corpid, corpsecret, agentid, sendTo, subject + ":" + content);
            return flag;
        }

    };

    @Override
    public void initializePlugin() {
        NoticeManager.register(NOTICE); // 注册到消息通知管理器中

    }

    @Override
    public void destroyPlugin() {

    }

    @Override
    public PluginInfo getPluginInfo() {
        return pluginInfo;
    }

}
